function switchTab(button) {
  var navButtons = document.querySelectorAll('.nav-button');
  navButtons.forEach(function (navButton) {
    navButton.classList.remove('active');
  });
  button.classList.add('active');
  updateContent(button.textContent);
}

function updateContent(text) {
  if (text === "填写简历") {
    document.getElementById('resumeFormContainer').style.display = 'block';
    document.querySelector('.content').style.display = 'none';
  } else {
    document.getElementById('resumeFormContainer').style.display = 'none';
    document.querySelector('.content').style.display = 'flex';
  }
}
function viewMyResume() {
  window.location.href = 'http://127.0.0.1:5501/sparkResume/html/users-choose.html';
}
function uploadResume() {
  const fileInput = document.getElementById('resumeFileInput');
  const file = fileInput.files[0];
  if (!file) {
    alert('请选择一个文件');
    return;
  }

  const formData = new FormData();
  formData.append('file', file);

  fetch(`http://192.168.244.14:8080/resumeStatus/upload/${usersId}`, {
    method: 'POST',
    body: formData
  })
    .then(response => {
      if (response.ok) {
        return response.json();
      } else {
        throw new Error('文件上传失败');
      }
    })
    .then(data => {
      if (data.code === 1) {
        displayFileLink(data.data);
      } else {
        alert('文件上传失败：' + data.msg);
      }
    })
    .catch(error => {
      console.error('文件上传请求出错:', error);
      alert('文件上传请求出错，请检查网络连接');
    });
}

function displayFileLink(fileUrl) {
  const fileDisplayArea = document.getElementById('fileDisplayArea');
  fileDisplayArea.innerHTML = `<a href="${fileUrl}" download>下载简历</a>`;
}
function uploadFile(usersId, file) {
  const formData = new FormData();
  formData.append('file', file);

  fetch(`http://192.168.244.14:8080/resumeStatus/upload/${usersId}`, {
    method: 'POST',
    body: formData
  })
    .then(response => {
      if (response.ok) {
        return response.json();
      } else {
        throw new Error('文件上传失败');
      }
    })
    .then(data => {
      if (data.code === 1) {
        displayFileLink(data.data);
        alert('文件上传成功');
      } else {
        alert('文件上传失败：' + data.msg);
      }
    })
    .catch(error => {
      console.error('文件上传请求出错:', error);
      alert('文件上传请求出错，请检查网络连接');
    });
}

function displayFileLink(fileUrl) {
  const fileDisplayArea = document.getElementById('fileDisplayArea');
  fileDisplayArea.innerHTML = `<a href="${fileUrl}" download>下载文件</a>`;
}

function uploadResume() {
  const userId = localStorage.getItem('userId');
  if (!userId) {
    alert('请先登录');
    return;
  }
  const fileInput = document.getElementById('resumeFileInput');
  const file = fileInput.files[0];
  if (!file) {
    alert('请选择一个文件上传');
    return;
  }
  uploadFile(userId, file);
}

